;
(function () {
  'use strict';

  var article_list, last_id;
  init_data();
  add('title', 'tf', 'content');
  console.log(s.get('article_list'))
  del(3);
  console.log(s.get('article_list'))

  function init_data() {
    article_list = s.get('article_list');
    last_id = s.get('last_id');

    if (!article_list) {
      article_list = [];
      s.set('article_list', article_list);
    };
    if (!last_id) {
      last_id = 0;
      s.set('last_id', last_id);
    };
  }

  function add(article_title, author, content) {
    article_list = s.get('article_list');
    var new_article = {
      id: s.get('last_id') + 1,
      article_title: article_title,
      author: author,
      content: content
    };
    article_list.push(new_article);
    inc();
    sync();
  };

  function find(index) {
    return article_list.findIndex(function (each) {
      if (each.id == index) {
        return true;
      };
    })
  };

  function del(id) {
    var index = find(id);
    if (index != -1) {
      article_list.splice(index, 1);
    };
    sync();
  };

  // function update(id, title, author, content) {
  //   var index = find_index(id);
  //   if (idnex === -1) {
  //     return;
  //   }
  //   var article = article_list[index];
  //   task.title = title;
  //   task.author = author;
  //   task.content = content;
  //   sync();
  // }

  function inc() {
    last_id = s.get('last_id');
    s.set('last_id', last_id + 1);
  };

  function sync() {
    s.set('article_list', article_list);
  };

})();